import 'dart:async';
import 'package:fake_handwriting/BGPainter.dart';
import 'package:fake_handwriting/generated/l10n.dart';
import 'package:flutter/material.dart';
class Splash extends StatefulWidget {
  const Splash({Key? key}) : super(key: key);
  @override
  SplashPage createState() => SplashPage();
}
class SplashPage extends State<Splash> {
  late Timer _timer1;
  late Timer _timer2;
  var _visible=false;
  startTime() async {
    _timer1 = Timer.periodic(const Duration(seconds: 1), (v) async {
      _timer1.cancel();
      _visible=true;
      setState(() {});
    });
    _timer2 = Timer.periodic(const Duration(seconds: 3), (v) async {
      _timer2.cancel();
      Navigator.pushReplacementNamed(context, "main_page");
    });
  }
  final List<CircleBean> _bobbleList = [];
  var visible = false;
  @override
  void initState() {
    super.initState();
    startTime();

    for(var i=0;i<3;i++){
      CircleBean bean = CircleBean();
      bean.color = const Color(0x15e6ebfd);
      if(i==0){
        bean.offset = const Offset(0, 500);
        bean.radius = 60;
      }
      if(i==1){
        bean.offset = const Offset(120, 150);
        bean.radius = 90;
      }
      if(i==2){
        bean.offset = const Offset(320, 500);
        bean.radius = 120;
      }
      _bobbleList.add(bean);
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: [
          Container(
            padding: const EdgeInsets.only(bottom: 100),
            width: double.infinity,
            height: double.infinity,
            color: Colors.blue,
            child:AnimatedOpacity(
              duration: const Duration(seconds: 1),
              opacity: _visible ? 1.0 : 0.0,
              child: Row(
                children: [
                  Image.asset("assets/logo.png",scale: 4,),
                  const SizedBox(
                    height: 20,
                  ),
                  Column(
                    children: [
                      Image.asset("assets/logo_font.png",scale: 6,),
                      Text(S.of(context).yourHandwritingAssistant,style: const TextStyle(
                          color: Colors.white,
                          fontSize: 10
                      ),),
                    ],mainAxisAlignment: MainAxisAlignment.center,
                  )
                ],mainAxisAlignment: MainAxisAlignment.center,
              ),
            ),
          ),
          CustomPaint(
            size: MediaQuery.of(context).size,
            painter: BGPainter(list: _bobbleList),
          ),
          AnimatedOpacity(
            duration: const Duration(seconds: 1),
            opacity: _visible ? 1.0 : 0.0,
            child: Padding(
              padding: const EdgeInsets.only(bottom: 20),
              child: Align(child: Text("${S.of(context).fakeHandwriting}©All rights reserved.",style: const TextStyle(
                  color: Colors.white,
                fontSize: 10
              ),),alignment: Alignment.bottomCenter,),
            ),
          ),
        ],
      ),
    );
  }
}
